home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / ned103.zip / EDITPKG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-28  |  34KB  |  1,156 lines

  1. { FILE:  editpkg.pas }
  2.  
  3.  
  4.  
  5. unit EditPkg;
  6.  
  7.  
  8.  
  9. { ************************************************************************* }
  10. {                                                                           }
  11. { NOTICE:  Most of the following code was written by Borland International. }
  12. {          The code is for use by TP6.0 users.  Keep the copyright notice   }
  13. {          intact!                                                          }
  14. {                                                                           }
  15. {          Turbo Pascal 6.0                                                 }
  16. {          Turbo Vision Demo                                                }
  17. {          Copyright (c) 1990 by Borland International                      }
  18. {                                                                           }
  19. { This unit provides an interface to the NEWEDIT unit.  Specifically,       }
  20. { it initializes the buffers, contains all the editor dialogs, handles all  }
  21. { allocation and deallocation of the clipboard, and of course opens up      }
  22. { the appropriate edit window when requested.                               }
  23. {                                                                           }
  24. { The major item I've changed here is how the "heap" is set up for          }
  25. { use by the editor buffers.  You can search for it using the HEAP          }
  26. { shown below.                                                              }
  27. {                                                                           }
  28. { In addition, I've added a procedure to show how to close editor windows   }
  29. { for external file processing and then reopen them to continue editing.    }
  30. { Look for the CHKSPL label.  This label is also defined in NEDEMO and      }
  31. { NEWEDIT, for it requires coding through all three units.                  }
  32. {                                                                           }
  33. { All other labels in this unit are defined in the NEWEDIT                  }
  34. { unit, they being mostly for dialog boxes and error messages.              }
  35. {                                                                           }
  36. { There are additional minor things, like how to use typecasting to set     }
  37. { editor defaults when opening a window.  These aren't labeled.             }
  38. {                                                                           }
  39. { Search   Description:                                                     }
  40. { ------   ------------                                                     }
  41. {                                                                           }
  42. { HEAP   - Added a feature to allow maximum or minimum heap allocation      }
  43. {          for use by the editors buffers.                                  }
  44. {                                                                           }
  45. { SPLCHK - Shows how to close an edit window to process a file              }
  46. {          (such as spell checking) and reopen the window when done.        }
  47. {                                                                           }
  48. { Al Andersen - 02/29/92.                                                   }
  49. {                                                                           }
  50. { ************************************************************************* }
  51.  
  52.  
  53. {$O+,F+,X+,S-,D-}
  54.  
  55.  
  56.  
  57. interface
  58.  
  59.  
  60.  
  61. uses
  62.  
  63.   Objects,
  64.   Drivers,
  65.   Views,
  66.   Dialogs,
  67.   StdDlg,
  68.   MsgBox,
  69.   App,
  70.   Buffers,
  71.   CmdFile,
  72.   NewEdit;
  73.  
  74.  
  75. VAR
  76.  
  77.   Clip_Window : NewEdit.PEditWindow;      { Object to hold the clip board. }
  78.  
  79.  
  80.  
  81.   { SPLCHK - Start. }
  82.  
  83.   procedure SpellIt;
  84.  
  85.   { SPLCHK - Stop. }
  86.  
  87.   procedure Deallocate_The_Clipboard;
  88.   procedure Deallocate_The_Editor;
  89.  
  90.   procedure Initialize_The_Clipboard;
  91.   procedure Initialize_The_Editor;
  92.  
  93.   function  Open_Editor (File_Name : Objects.FNameStr;
  94.                          Visible   : Boolean) : NewEdit.PEditWindow;
  95.  
  96.   procedure Run_The_Editor;
  97.   procedure Show_ClipBoard;
  98.  
  99.  
  100.  
  101. implementation
  102.  
  103.  
  104.  
  105. { -------------------------------------------------------------------------- }
  106.  
  107.  
  108.  
  109. { SPLCHK - Start. }
  110.  
  111.  
  112.  
  113. Procedure SpellIt;
  114.  
  115.  
  116.   { ---------------------------------------------------------------------- }
  117.   {                                                                        }
  118.   { This procedure demonstrates how to close an editor window for external }
  119.   { file processing, and then reopen the window to continue editing.  The  }
  120.   { procedure assumes an external spell checking program will be used.     }
  121.   {                                                                        }
  122.   { ---------------------------------------------------------------------- }
  123.  
  124.  
  125. VAR
  126.  
  127.   SpellFileName : Objects.FNameStr; { Determines what the filename is. }
  128.  
  129. begin
  130.  
  131.  
  132.   { ----------------------------------------------------------- }
  133.   {                                                             }
  134.   { First we check to make sure that the current window is in   }
  135.   { fact an editor window.  We need to do this so you don't run }
  136.   { the spelling checker unless an edit window is being used.   }
  137.   {                                                             }
  138.   { ----------------------------------------------------------- }
  139.  
  140.  
  141.   if typeof (Desktop^.Current^) = typeof (TEditWindow) then
  142.     begin
  143.  
  144.  
  145.       { --------------------------------------------------------- }
  146.       {                                                           }
  147.       { OK, now get the filename associated with the current edit }
  148.       { window.  Then send a message to NewEdit.TFileEditor's     }
  149.       { HandleEvent method to write the data to disk and close    }
  150.       { the window.  You need to *REMOVE* the dialog and insert   }
  151.       { your spell checking code in its place.  Last of all you   }
  152.       { call Open_Editor to reopen your edit window.              }
  153.       {                                                           }
  154.       { --------------------------------------------------------- }
  155.  
  156.  
  157.       SpellFileName := NewEdit.PEditWindow (Desktop^.Current)^.Editor^.FileName;
  158.  
  159.       Message (Desktop^.Current,
  160.                Drivers.evCommand,
  161.                NewEdit.cmSaveDone,
  162.                nil);
  163.  
  164.       Msgbox.MessageBox (^C'Now your spellchecker does its thing.',
  165.                          nil, MsgBox.mfInformation + MsgBox.mfOKButton);
  166.  
  167.       Open_Editor (SpellFileName, True);
  168.  
  169.     end;
  170.  
  171.  
  172. end; { SpellIt }
  173.  
  174.  
  175.  
  176. { SPLCHK - Stop. }
  177.  
  178.  
  179.  
  180. { -------------------------------------------------------------------------- }
  181.  
  182.  
  183.  
  184. function Execute_Dialog (P : Dialogs.PDialog; Data : Pointer) : Word;
  185.  
  186.  
  187.   { -------------------------------------------------------- }
  188.   {                                                          }
  189.   { This function places the editor dialogs on the desktop   }
  190.   { and takes care of seting/getting data options from them. }
  191.   {                                                          }
  192.   { -------------------------------------------------------- }
  193.  
  194.  
  195. VAR
  196.  
  197.   Result : Word; { Holds result of trying to ExecView onto Desktop. }
  198.  
  199. begin
  200.  
  201.   Result := Views.cmCancel;
  202.  
  203.   P := PDialog (App.Application^.ValidView (P));
  204.  
  205.   if P <> nil then
  206.   begin
  207.  
  208.     if Data <> nil then
  209.       P^.SetData (Data^);
  210.  
  211.     Result := App.DeskTop^.ExecView (P);
  212.  
  213.     if (Result <> Views.cmCancel) and (Data <> nil) then
  214.       P^.GetData (Data^);
  215.  
  216.     Dispose (P, Done);
  217.  
  218.   end;
  219.  
  220.   Execute_Dialog := Result;
  221.  
  222.  
  223. end; { Execute_Dialog }
  224.  
  225.  
  226.  
  227. { -------------------------------------------------------------------------- }
  228.  
  229.  
  230.  
  231. function Do_Edit_Dialog (Dialog : Integer; Info : Pointer) : Word; far;
  232.  
  233.  
  234.   { ---------------------------------------------------------- }
  235.   {                                                            }
  236.   { This function creates the appropriate editor dialog boxes. }
  237.   {                                                            }
  238.   { ---------------------------------------------------------- }
  239.  
  240.  
  241. VAR
  242.  
  243.   Y_Position : Word; { Local variable to ensure ALL dialogs start in same spot. }
  244.  
  245.  
  246.  
  247.